﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;

namespace KouSuan
{
    /// <summary>
    /// ExamWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ExamWindow : Window, INotifyPropertyChanged
    {
        int curTabIndex = 0;
        TextBox curTextBox;

        public ExamWindow()
        {
            InitializeComponent();
        }

        private void ResizeListViewItem()
        {
            double width = listView.ActualWidth;
            double mod = (width % 245) / 2 - 13;
            listView.Padding = new Thickness(mod, 0, mod, 0);
        }

        private void TextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            curTextBox = sender as TextBox;
            curTabIndex = curTextBox.TabIndex;
        }

        private void listView_KeyUp(object sender, KeyEventArgs e)
        {

        }

        private void listView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Tab && curTabIndex == listView.Items.Count - 1)
            {
                btnSubmit.Focus();
                e.Handled = true;
            }
        }

        private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            listView.SelectedIndex = -1;
            if (curTextBox != null)
            {
                curTextBox.Focus();
            }
            e.Handled = true;
        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ResizeListViewItem();
        }

        private void RaisePropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
